package study.redis;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.lettuce.LettuceConnection;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class RedisTest {
    private static final String host = "192.168.5.56";
    private static final int port = 6379;
    private static final String password = "123456";
    private static final int database = 1;

    public static void main(String[] args) {
        RedisConnection conn = new LettuceConnection(5, redisClient());
        System.out.println(conn.set("ping".getBytes(StandardCharsets.UTF_8), "pong".getBytes(StandardCharsets.UTF_8)));
        System.out.println(Arrays.toString(conn.get("hello".getBytes(StandardCharsets.UTF_8))));
    }

    static RedisClient redisClient() {
        RedisURI uri = RedisURI.Builder.redis(host, port)
            .withPassword(password)
            .withDatabase(database)
            .build();
        return RedisClient.create(uri);
    }
}
